package cn.s1995.sloth.bizs.service.impl;

import cn.s1995.sloth.bizs.constant.RedisKeyCst;
import cn.s1995.sloth.bizs.entity.UserVisitorRecord;
import cn.s1995.sloth.bizs.mapper.UserVisitorRecordMapper;
import cn.s1995.sloth.bizs.service.UserVisitorRecordService;
import cn.s1995.sloth.bizs.util.RedisUtil;
import cn.s1995.sloth.common.core.util.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
/**
 * 用户访问记录
 *
 * @author Lex
 * @date 2024-05-25 11:02:45
 */
@Service
public class UserVisitorRecordServiceImpl extends ServiceImpl<UserVisitorRecordMapper, UserVisitorRecord> implements UserVisitorRecordService {

    @Resource
    private RedisUtil redisUtil;

    @Async
    @Override
    public void addUserVisitor(Long uid) {
        String admin = "admin";
        UserVisitorRecord userVisitorRecord = new UserVisitorRecord();
        userVisitorRecord.setUid(uid);
        userVisitorRecord.setCreateBy(admin);
        userVisitorRecord.setUpdateBy(admin);
        boolean save = save(userVisitorRecord);
        if (save) {
            redisUtil.set(RedisKeyCst.USER_VISITOR + uid, uid, DateUtil.getTodayRemainingTime());
        }
    }
}
